/**
@description base文件

@copyright    Copyright 2021 高灯科技
@version      1.0.0
@link         https://www.goldentec.com
@author       venki.chen <venki.chen@goldentec.com>
@datetime     2021/11/16 9:37
*/

package base

import (
	"fmt"
)

func init() {
	fmt.Println("base模块初始化成功……")
}

//
// Human
//  @Description:
//  @author venki.chen
//  @createdtime 2021-11-16 13:33:55
//
type Human struct {
	name string
	sex  string
}

// Superman
//  @Description:
//  @author venki.chen
//  @createdtime 2021-11-16 13:33:46
//
type Superman struct {
	Human
	level int
}

//
//	AccessBase
//	@Description
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 13:33:44
//  @updatedtime 2021-11-16 13:33:44
//
func AccessBase() {
	// deferLearn()
	// deferAndReturn()
	// arrayLearn()
	// sliceLearn()
	// mapLearn()
	structLearn()
}

//
//	structLearn
//	@Description
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 13:33:41
//  @updatedtime 2021-11-16 13:33:41
//
func structLearn() {
	h := Human{
		name: "陈文小超",
		sex:  "male",
	}
	h.Eat()
	h.Walk()

	var superman Superman
	superman.name = "venki.chen"
	superman.sex = "female"
	superman.level = 99
	superman.Eat()
	superman.Walk()
	superman.Fly()
	superman.Print()
}

//
//	Eat
//	@Description
//	@receiver this *Superman
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 13:33:37
//  @updatedtime 2021-11-16 13:33:37
//
func (this *Superman) Eat() {
	fmt.Println("superman eat()...")
}

//
//	Fly
//	@Description
//	@receiver this *Superman
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 13:33:21
//  @updatedtime 2021-11-16 13:33:21
//
func (this *Superman) Fly() {
	fmt.Println("superman fly()...")
}

//
//	Print
//	@Description
//	@receiver this *Superman
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 13:33:17
//  @updatedtime 2021-11-16 13:33:17
//
func (this *Superman) Print() {
	fmt.Println("superman is name=", this.name)
	fmt.Println("superman is sex=", this.sex)
	fmt.Println("superman is level=", this.level)
}

//
//	Eat
//	@Description
//	@receiver this *Human
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 13:33:14
//  @updatedtime 2021-11-16 13:33:14
//
func (this *Human) Eat() {
	fmt.Println("human.eat()……")
}

//
//	Walk
//	@Description
//	@receiver this *Human
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 13:33:04
//  @updatedtime 2021-11-16 13:33:04
//
func (this *Human) Walk() {
	fmt.Println("human.walk()……")
}

//
//	mapLearn
//	@Description
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 11:37:14
//  @updatedtime 2021-11-16 11:37:14
//
func mapLearn() {
	// 声明方式1 - 只是声明没有分配空间
	var map01 map[string]string
	map01 = make(map[string]string, 10)
	map01["one"] = "venki"
	map01["two"] = "chen"
	fmt.Println("map声明方式01，map01=", map01)

	// 声明方式02
	map02 := make(map[int]string)
	map02[0] = "poet"
	map02[1] = "chao"
	fmt.Println("map声明方式02，map02=", map02)

	// 声明方式03
	map03 := map[int]string{
		0: "陈",
		1: "文",
		2: "小",
		3: "超",
	}
	fmt.Println("map声明方式03，map03=", map03)

	// 增加
	map04 := make(map[string]string)
	map04["chen"] = "陈"
	map04["wen"] = "文"
	map04["xiao"] = "小"
	map04["chao"] = "超"
	fmt.Println("map使用方式之增加元素，map04=", map04)
	// 删除
	delete(map04, "chen")
	fmt.Println("map使用方式之删除元素，map04=", map04)
	// 修改
	map04["xiao"] = "大"
	fmt.Println("map使用方式之修改元素，map04=", map04)
	// 查询
	i := 0
	for index, value := range map04 {
		i++
		fmt.Printf("map04第%d个元素的索引下标是%v,对应的值是%v\n", i, index, value)
	}
}

//
//	sliceLearn
//	@Description
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 11:45:18
//  @updatedtime 2021-11-16 11:45:18
//
func sliceLearn() {
	// 声明方式1 - 并初始化，默认值1,2,3,4 长度为4
	slice01 := []int{1, 2, 3, 4}
	fmt.Println("切片声明方式01，slice01=", slice01)

	// 声明方式2 - 但是并没有给slice分配空间，没有分配空间直接赋值，会报错
	var slice02 []int
	slice02 = make([]int, 3) // 开辟3个空间，初始化值均是0
	fmt.Println("切片声明方式02，slice02=", slice02)

	// 声明方式3 - 同时给slice分配空间，初始化值0
	var slice03 []int = make([]int, 3)
	fmt.Println("切片声明方式03，slice03=", slice03)

	// 声明方式4 - 类型推导，同时分配空间初始化值【以这种方式声明为标准】
	slice04 := make([]int, 3)
	fmt.Println("切片声明方式04，slice04=", slice04)

	// 切片的使用方式
	var slice05 []int = make([]int, 3, 5)
	slice05[0] = 1
	slice05[1] = 2
	slice05[2] = 3
	slice05 = append(slice05, 4)
	slice05 = append(slice05, 5)

	fmt.Println(slice05)

	var slice06 []int = make([]int, 3, 5)

	copy(slice06, slice05)
	fmt.Println(slice06)
	slice06[0] = 100
	fmt.Println(slice05)
	fmt.Println(slice06)

}

//
//	arrayLearn
//	@Description
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 11:45:21
//  @updatedtime 2021-11-16 11:45:21
//
func arrayLearn() {

}

//
//	deferAndReturn
//	@Description
//	@return int
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 11:45:23
//  @updatedtime 2021-11-16 11:45:23
//
func deferAndReturn() int {
	defer deferCall()
	return returnCall()
}

//
//	deferCall
//	@Description
//	@return int
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 11:45:25
//  @updatedtime 2021-11-16 11:45:25
//
func deferCall() int {
	fmt.Println("defer func call!")
	return 0
}

//
//	returnCall
//	@Description
//	@return int
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 11:45:28
//  @updatedtime 2021-11-16 11:45:28
//
func returnCall() int {
	fmt.Println("return func call!")
	return 0
}

//
//	deferLearn
//	@Description
//  @maxim from focus to execute
//  @author venki.chen
//  @createdtime 2021-11-16 11:45:32
//  @updatedtime 2021-11-16 11:45:32
//
func deferLearn() {
	defer fmt.Println("我是defer01，程序结束前调用我哦！")
	defer fmt.Println("我是defer02，程序结束前调用我哦！")

	fmt.Println("程序执行到此01")
	fmt.Println("程序执行到此02")
}
